package com.copa.gameStore.exception;

import com.copa.gameStore.vo.ResponseVo;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author copa
 * @createDate 2022-09-22 18:16
 * @function
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(AuthenticationException.class)
    public ResponseVo<String> authenticationExceptionHandler(AuthenticationException ex){
        return ResponseVo.errorMsg("认证异常：" + ex.getMessage());
    }

    @ResponseBody
    @ExceptionHandler(UsernameNotFoundException.class)
    public ResponseVo<String> usernameNotFoundExceptionHandler(UsernameNotFoundException ex){
        return ResponseVo.errorMsg("错误：" + ex.getMessage());
    }


}
